package com.vteba.shards.schema.service;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import com.vteba.shards.schema.model.SchemaInfo;

/**
 * 当前应用的数据库schema信息持有者
 * @author yinlei
 * @date 2014年11月25日 上午10:35:30
 */
public class SchemaHolder {
	private static ConcurrentMap<String, SchemaInfo> schemaMap = new ConcurrentHashMap<String, SchemaInfo>();

	public static ConcurrentMap<String, SchemaInfo> getSchemaMap() {
		return schemaMap;
	}

	public static void setSchemaMap(ConcurrentMap<String, SchemaInfo> schemaMap) {
		if (schemaMap == null) {
			return;
		}
		SchemaHolder.schemaMap = schemaMap;
	}
	
	/**
	 * 添加一个新的schema信息
	 * @param schemaName schema名字
	 * @param schemaInfo schema
	 */
	public static void add(String schemaName, SchemaInfo schemaInfo) {
		schemaMap.put(schemaName, schemaInfo);
	}
	
	/**
	 * 删除对应的schema，返回该schemaName对应的旧的SchemaInfo
	 * @param schemaName schema名字
	 * @return
	 */
	public static SchemaInfo remove(String schemaName) {
		return schemaMap.remove(schemaName);
	}
}
